﻿
using System;
using System.Threading;

namespace tests2
{
    class Program
    {
        static void Main(string[] args)
        {
            const int COUNT = Int32.MaxValue;
            const int COUNT2 = 10;
            int j = 0;
            Console.WriteLine(DateTime.Now);
            for (int i = 0; i < COUNT; i++)
            {
                j = 0;
                for (int k = 0; k < COUNT2; k++)
                {
                    unchecked { j++; }
                }
            }
            Console.WriteLine(DateTime.Now);
            for (int i = 0; i < COUNT; i++)
            {
                j = 0;
                for (int k = 0; k < COUNT2; k++)
                {
                    checked { j++; }
                }
            }
            Console.WriteLine(DateTime.Now);
            for (int i = 0; i < COUNT; i++)
            {
                j = 0;
                for (int k = 0; k < COUNT2; k++)
                {
                    Interlocked.Increment(ref j);
                }
            }
            Console.WriteLine(DateTime.Now);
            for (int i = 0; i < COUNT; i++)
            {
                j = 0;
                for (int k = 0; k < COUNT2; k++)
                {
                    Interlocked.Add(ref j, 1);
                }
            }
            Console.WriteLine(DateTime.Now);
        }
    }
}
